package com.leyou.page.controller;

import com.leyou.page.service.FileService;
import com.leyou.page.service.impl.PageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * Author: Saka
 * Date: 2019/2/19
 * Time: 16:56
 */
@Controller
public class PageController {

    @Autowired
    private PageServiceImpl pageService;

    @Autowired
    private FileService fileService;

    @GetMapping("item/{spuId}.html")
    public String toPage(@PathVariable("spuId") Long spuId, Model model) {
        // 根据spuid查询相关信息,返回结果为map
        model.addAllAttributes(pageService.toPage(spuId));

        // 判断是否需要生成新的页面
        if(!this.fileService.exists(spuId)){
            //this.fileService.syncCreateHtml(spuId);
        }

        return "item";
    }
}
